package com.shisfish.library.Controller;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.shisfish.library.Impl.UserLevelImpl;
import com.shisfish.library.Model.UserLevel;
import com.shisfish.library.Utils.Global.GlobalVariable;
import com.shisfish.library.Utils.Global.toJsonUtils;

@Path("userLevel")
public class UserLevelController extends GlobalVariable {
	
	UserLevelImpl userLevelImpl = new UserLevelImpl();
	
	@POST
	@Path("insertOne/{idadmin}")
	@Produces("application/json; charset=utf-8")
	public String insertOne(@PathParam("idadmin") String idadmin, @FormParam("name") String name, 
			@FormParam("borrow_numbers") int borrow_numbers, @FormParam("borrow_days") int borrow_days, 
			@FormParam("loan_numbers") int loan_numbers, @FormParam("loan_borrow_days") int loan_borrow_days) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		UserLevel userLevel = new UserLevel(name, borrow_numbers, borrow_days, loan_numbers, loan_borrow_days);
		
		int flag = userLevelImpl.insertOne(userLevel);
		
		if (flag == 1) {
			globalMap.put("message", ADD_SUCCESS);
		}
		
		return toJsonUtils.map2Json(globalMap);
	}
	
}
